#include <bits/stdc++.h>
using namespace std;
int Min(int number1,int number2,int number3)
{
    int min = (number1<number2)?number1:number2;
    min = (min<number3)?min:number3;
    return min;
}
int GetUglyNumber(int index)
{
    if(index<=0)
        return 0;
    int *puglynumber = new int[index];
    puglynumber[0] = 1;
    int nextuglyindex = 1;
    int *pMut2 = puglynumber;
    int *pMut3 = puglynumber;
    int *pMut5 = puglynumber;
    while(nextuglyindex<index)
    {
        int min = Min(*pMut2*2,*pMut3*3,*pMut5*5);
        puglynumber[nextuglyindex] = min;
        while(*pMut2*2<=puglynumber[nextuglyindex])
            ++pMut2;
        while(*pMut3*3<=puglynumber[nextuglyindex])
            ++pMut3;
        while(*pMut5*5<=puglynumber[nextuglyindex])
            ++pMut5;
        ++nextuglyindex;
    }
    int ugly = puglynumber[nextuglyindex-1];
    for(int i=0;i<10;i++)
        cout<<puglynumber[i]<<endl;
    delete [] puglynumber;
    return ugly;
}

int main() {
    cout<<GetUglyNumber(10);
    return 0;
}